#include "plugin.h"
#include "icons.h"
#include "stddump.h"
#include "resource.h"

/*====================================================================================
CBINITDEBUG - Called by debugger when a program is debugged - needs to be EXPORTED

Arguments: cbType
cbInfo - a pointer to a PLUG_CB_INITDEBUG structure.
The szFileName item contains name of file being debugged.

--------------------------------------------------------------------------------------*/
//PLUG_EXPORT void CBINITDEBUG(CBTYPE cbType, PLUG_CB_INITDEBUG* info)
//{
//}
//
//PLUG_EXPORT void CBSTOPDEBUG(CBTYPE cbType, PLUG_CB_STOPDEBUG* info)
//{
//}
//
//PLUG_EXPORT void CBEXCEPTION(CBTYPE cbType, PLUG_CB_EXCEPTION* info)
//{
//}
//
//PLUG_EXPORT void CBDEBUGEVENT(CBTYPE cbType, PLUG_CB_DEBUGEVENT* info)
//{
//}
//
//PLUG_EXPORT void CBCREATEPROCESS(CBTYPE cbType, PLUG_CB_CREATEPROCESS* info)
//{
//}
//
//PLUG_EXPORT void CBLOADDLL(CBTYPE cbType, PLUG_CB_LOADDLL* info)
//{
//}
//
///*====================================================================================
//CBSYSTEMBREAKPOINT - Called by debugger at system breakpoint - needs to be EXPORTED
//
//Arguments: cbType
//cbInfo - reserved
//
//--------------------------------------------------------------------------------------*/
//PLUG_EXPORT void CBSYSTEMBREAKPOINT(CBTYPE cbType, PLUG_CB_SYSTEMBREAKPOINT* info)
//{
//}

/*PLUG_EXPORT void CBWINEVENT(CBTYPE cbType, PLUG_CB_WINEVENT* info)
{
	OnWinEvent(info);
}*/

PLUG_EXPORT void CBBREAKPOINT(CBTYPE cbType, PLUG_CB_BREAKPOINT* bpInfo)
{
	OnBreakpoint(bpInfo);
}

/*====================================================================================
CBMENUENTRY - Called by debugger when a menu item is clicked - needs to be EXPORTED

Arguments: cbType
cbInfo - a pointer to a PLUG_CB_MENUENTRY structure. The hEntry contains
the resource id of menu item identifiers

Notes:     hEntry can be used to determine if the user has clicked on your plugins
menu item(s) and to do something in response to it.

--------------------------------------------------------------------------------------*/
PLUG_EXPORT void CBMENUENTRY(CBTYPE cbType, PLUG_CB_MENUENTRY* info)
{
	MSGBOXPARAMS mbp = { 0 };
	switch(info->hEntry)
    {
		// OPTIONS MENUS
		// ------------------------------------------------------------------------
		case MENU_STL_UNDEF:
			SaveConfig();
			break;
		case MENU_STL_MAP_INT_INT:
			DumpSTLMap("int", "int");
			break;
		case MENU_STL_MAP_INT_PCHAR:
			DumpSTLMap("int", "char*");
			break;
		case MENU_STL_MAP_INT_STRING:
			DumpSTLMap("int", "string");
			break;
		case MENU_STL_MAP_PCHAR_INT:
			DumpSTLMap("char*", "int");
			break;
		case MENU_STL_MAP_STRING_INT:
			DumpSTLMap("string", "int");
			break;
		case MENU_STL_MAP_STRING_STRING:
			DumpSTLMap("string", "string");
			break;
	
			break;
		case MENU_ABOUT:
 			ZeroMemory(&mbp, sizeof(MSGBOXPARAMS));
 			mbp.cbSize = sizeof(MSGBOXPARAMS);
 			mbp.hInstance = pluginHInstance;
 			mbp.lpszCaption = "About...";
 			mbp.lpszText = "[" PLUGIN_NAME " " PLUGIN_VERSION_STR"]\n"
 							"Dump C++ STL object \n\n"
 							"Coded By : Snow - 2020";
 			mbp.dwStyle = MB_USERICON | MB_OK;
 			mbp.lpszIcon = MAKEINTRESOURCE(IDI_ICON1);
 			MessageBoxIndirect(&mbp);
			break;		
		
		default:
			break;
    }
}

//--------------------------------------------------------------------------------------
//Initialize your plugin data here.
bool pluginInit(PLUG_INITSTRUCT* initStruct)
{
	string faultyFile;
	string folder;
	int errorLine = -1;
	char message[MAX_COMMENT_SIZE] = "";

	GetCurrentDirectory(MAX_PATH, szCurrentDirectory);
	strcat_s(szCurrentDirectory, "\\");

	config_path = szCurrentDirectory + string("StdDump.ini");

    return true; //Return false to cancel loading the plugin.
}

//--------------------------------------------------------------------------------------
//Deinitialize your plugin data here (clearing menus optional).
bool pluginStop()
{
    _plugin_menuclear(hMenu);
    _plugin_menuclear(hMenuDisasm);
    _plugin_menuclear(hMenuDump);
    _plugin_menuclear(hMenuStack);
    return true;
}

//--------------------------------------------------------------------------------------
//Do GUI/Menu related things here.
void pluginSetup()
{
	ICONDATA menu_icon;
	ICONDATA anal_function_icon;
	ICONDATA anal_select_icon;
	ICONDATA anal_exe_icon;

	ICONDATA remove_exe_icon;
	ICONDATA remove_function_icon;
	ICONDATA remove_selection_icon;

	menu_icon.data = icon;
	menu_icon.size = sizeof(icon);

	anal_function_icon.data = anal_function;
	anal_function_icon.size = sizeof(anal_function);
	anal_exe_icon.data = anal_exe;
	anal_exe_icon.size = sizeof(anal_exe);
	anal_select_icon.data = anal_selection;
	anal_select_icon.size = sizeof(anal_selection);

	remove_exe_icon.data = exe_remove;
	remove_exe_icon.size = sizeof(exe_remove);
	remove_function_icon.data = function_remove;
	remove_function_icon.size = sizeof(function_remove);
	remove_selection_icon.data = selection_remove;
	remove_selection_icon.size = sizeof(selection_remove);

	LoadConfig();

	// plugin menu
	_plugin_menuaddentry(hMenu, MENU_ABOUT, "&About...");

	// disasm window menu
	_plugin_menuseticon(hMenuDump, &menu_icon);
	_plugin_menuaddentry(hMenuDump, MENU_STL_MAP_INT_INT, "map<int,int>");
	_plugin_menuaddentry(hMenuDump, MENU_STL_MAP_INT_PCHAR, "map<int,char*>");
	_plugin_menuaddentry(hMenuDump, MENU_STL_MAP_INT_STRING, "map<int,string>");
	_plugin_menuaddseparator(hMenuDump);
	_plugin_menuaddentry(hMenuDump, MENU_STL_MAP_PCHAR_INT, "map<char*,int>");
	_plugin_menuaddentry(hMenuDump, MENU_STL_MAP_STRING_INT, "map<string,int>");
	_plugin_menuaddentry(hMenuDump, MENU_STL_MAP_STRING_STRING, "map<string,string>");

}
//--------------------------------------------------------------------------------------